package com.chinasoftinc.facommon.control.service;

import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.rpc.IRemoteObject;

import com.huawei.ailife.service.kit.AiLifeServiceHelper;

import com.chinasoftinc.facommon.utils.LogUtil;

/**
 * @since 2022-05-13
 */
public class HilinkDeviceServiceAbility extends Ability {
    private static final String TAG = "BleServiceAbility";
    private static HilinkDeviceRemote remote = null;

    @Override
    public void onStart(Intent intent) {
        LogUtil.error(TAG, "onStart");
        AiLifeServiceHelper.initApplication(getAbilityPackage());
        remote = new HilinkDeviceRemote();
        super.onStart(intent);
    }

    @Override
    public void onBackground() {
        super.onBackground();
        LogUtil.info(TAG, "onBackground");
    }

    @Override
    public void onStop() {
        super.onStop();
        AiLifeServiceHelper.disconnect();
        LogUtil.info(TAG, "onStop");
    }

    @Override
    public IRemoteObject onConnect(Intent intent) {
        LogUtil.info(TAG, "onConnect");
        super.onConnect(intent);
        return remote.asObject();
    }

    @Override
    public void onDisconnect(Intent intent) {
        LogUtil.info(TAG, "onDisconnect remote:" + remote);
        if (remote != null) {
            remote.disconnect();
        }
    }
}